package com.loong.musicdemo.ui.find.activity.ui.detail.fragment;

import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.loong.musicdemo.R;
import com.loong.musicdemo.model.Singer;
import com.loong.musicdemo.util.dataDeal.SingerDeal;

import java.util.Map;

public class SingerAboutFragment extends Fragment {
    private LinearLayout infoLayout;
    private String singerId ;
    public SingerAboutFragment(String singerId) {
        this.singerId = singerId;
    }


    public static SingerAboutFragment newInstance(String singerId ) {
        SingerAboutFragment fragment = new SingerAboutFragment(singerId);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_singer_about, container, false);
        infoLayout = view.findViewById(R.id.singer_info);
        new AboutTask().execute();
        return view;
    }
    class AboutTask extends AsyncTask<String ,Void, Map<String,String>>{
        @Override
        protected void onPostExecute(Map<String, String> infoMap) {
            super.onPostExecute(infoMap);
            for (Map.Entry<String, String> entry : infoMap.entrySet()) {
                TextView title = new TextView(getContext());
                title.setText(entry.getKey());
                title.setTextSize(18);
                title.setPadding(0,0,0,10);
                TextView content = new TextView(getContext());
                content.setText(entry.getValue());
                content.setTextColor(Color.rgb(153,154,170));
                content.setTextSize(14);
                content.setPadding(0,0,0,20);
                infoLayout.addView(title);
                infoLayout.addView(content);
            }
        }

        @Override
        protected Map<String, String> doInBackground(String... strings) {
            return SingerDeal.getSingerInfoById(singerId);
        }
    }
}